<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class Login extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'phone' => 'bail|required|exists:users,phone|regex:/^1[34578][0-9]{9}$/',
            'password' => 'bail|required',
            'geetest_challenge' => 'geetest',
        ];
    }

    public function messages()
    {
        return [
            'phone.required' => '请输入手机号',
            'phone.exists' => '没有该用户',
            'phone.regex' => '手机号格式错误',

            'password.required' => '请输入密码',
            'geetest' => config('geetest.server_fail_alert')
        ];
    }
}
